# -*- Mode: Makefile for CI checks -*-

top_builddir?=../..
top_srcdir?=../..
OUT?=.
libcoap?=libcoap-2
WARNING_CFLAGS?=-pedantic -Wall -Wcast-qual -Wextra -Wformat-security -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wunused -Wwrite-strings  -Wlogical-op -Wunused-result
DTLS_CFLAGS?=
DTLS_LIBS?=
CPPFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include
CFLAGS=$(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99
CFLAGS+=-Wno-missing-prototypes -Wno-missing-declarations

SOURCES:=$(wildcard *_target.c)
OBJECTS:= $(patsubst %.c, $(OUT)/%.o, $(SOURCES))
PROGRAMS:=$(patsubst %_target.o, %_fuzzer, $(OBJECTS))

.PHONY: all check

all: $(PROGRAMS)

$(OUT)/%.o: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o $@

%_fuzzer: %_target.o
	$(LINK.cc) $(CXXFLAGS) $^ $(top_builddir)/.libs/$(libcoap).a $(LDFLAGS) $(LDLIBS) $(DTLS_LIBS) -o $@

check: $(OBJECTS)

clean:
	@-$(RM) $(OBJECTS) $(PROGRAMS)
